package com.dwxt.community.admin.controller;

import com.dwxt.common.base.*;
import com.dwxt.common.util.ExcelUtils;
import com.dwxt.community.aiequipment.aibin.entity.*;
import com.dwxt.community.aiequipment.aibin.service.*;
import com.dwxt.community.dao.TrashIntegralRecoadMapper;
import com.dwxt.community.entity.*;
import com.dwxt.community.entity.vo.TrashIntegralRecoadVo;
import com.dwxt.community.exception.DefinedException;
import com.github.pagehelper.*;
import org.apache.commons.lang3.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.*;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @program: intelligentcity
 * @description: 智能垃圾箱 后台
 * @author
 * @create: 2020/04/18
 */
@RestController
@RequestMapping("/cms/admin/trashCan")
public class TrashCanControllerAdmin {

    @Autowired
    private TrashCanService trashCanService;
    @Autowired
    private TrashIntegralRecoadService trashIntegralRecoadService;
    @Autowired
    private TrashIntegralRecoadMapper trashIntegralRecoadMapper;

    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":[{"deviceId":"431966353339464D05D8FF33","address":"1,聚金万佳苑,10栋32-6","waterLine":12,"temperature":40,"weight":30,"wsTime":1587069538000,"iccId":"iccid"}]}
     * @catalog 社区后台管理/智能垃圾箱
     * @title 垃圾箱列表
     * @param pageNum 非必须 Integer 当前页
     * @param pageSize 非必须 Integer 每页条数
     * @method get
     * @description 垃圾箱列表
     * @url /cms/admin/trashCan/get
     */
    @RequestMapping("/get")
    public BaseResult get(@RequestParam(defaultValue = "1") Integer pageNum,
                          @RequestParam(defaultValue = "10") Integer pageSize,
                          Integer using,
                          String name) {
        return BaseResult.ok(new PageInfo<>(trashCanService.get(pageNum, pageSize,name,using)));
    }
    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":[{"deviceId":"431966353339464D05D8FF33","address":"1,聚金万佳苑,10栋32-6","waterLine":12,"temperature":40,"weight":30,"wsTime":1587069538000,"iccId":"iccid"}]}
     * @catalog 社区后台管理/智能垃圾箱
     * @title 没有绑定督导员的垃圾箱列表
     * @param pageNum 非必须 Integer 当前页
     * @param pageSize 非必须 Integer 每页条数
     * @method get
     * @description 垃圾箱列表
     * @url /cms/admin/trashCan/getTrashCanForNotSupervisor
     */
    @RequestMapping("/getTrashCanForNotSupervisor")
    public BaseResult getTrashCanForNotSupervisor(@RequestParam(defaultValue = "1") Integer pageNum,
                          @RequestParam(defaultValue = "10") Integer pageSize) {
        return BaseResult.ok(new PageInfo<>(trashCanService.getTrashCanForNotSupervisor(pageNum, pageSize)));
    }

    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":{"deviceId":"431966353339464D05D8FF33","location":"29.5497983800,106.5167420100","address":"聚金万佳苑10号楼前门","waterLine":120,"temperature":40,"weight":30,"capacity":60,"wsTime":1587069538000,"batteryVoltage":2,"binCount":2,"batteryTemperatur":35,"mainboardTemperature":35,"iccId":"iccid","communityId":1,"status":0}}
     * @catalog 社区后台管理/智能垃圾箱
     * @title 垃圾箱详情
     * @method get
     * @param id 必须 String 分类桶ID
     * @description 垃圾箱详情
     * @url /cms/admin/trashCan/detail
     */
    @RequestMapping("/detail")
    public BaseResult get(String id) {
        if (StringUtils.isBlank(id)) {
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return BaseResult.ok(trashCanService.detail(id));
    }

    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":[{"tirId":1,"userId":"158502014539731","houseAddr":"1,聚金万佳苑,10栋32-6","createTime":"2020-04-15 12:11:51","delivererId":"158502014539731","gotIntegral":20,"totalIntegral":500,"trashType":1,"deliverWeight":20},{"tirId":2,"userId":"158502014539731","houseAddr":"1,聚金万佳苑,10栋32-6","createTime":"2020-04-15 12:11:53","delivererId":"158502014539731","gotIntegral":15,"totalIntegral":515,"trashType":2,"deliverWeight":15}]}
     * @catalog 社区后台管理/智能垃圾箱
     * @title 投递积分记录列表
     * @param pageNum 非必须 Integer 当前页
     * @param pageSize 非必须 Integer 每页条数
     * @param deviceId 非必须 String 分类桶ID
     * @param userId 非必须 String 用户ID
     * @param delivererId 非必须 String 投递者ID
     * @param gotIntegral 非必须 Integer 积分信息
     * @method get
     * @description 积分记录列表
     * @url /cms/admin/trashCan/record
     */
    @RequestMapping("/record")
    public BaseResult record(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             TrashIntegralRecoadVo trashIntegralRecoadVo,
                             Integer excel) {
        return BaseResult.ok(new PageInfo<>(trashIntegralRecoadService.selectAll(pageNum, pageSize,trashIntegralRecoadVo,excel)));
    }
    @RequestMapping("/recordExport")
    public void recordExport(HttpServletResponse response, TrashIntegralRecoadVo trashIntegralRecoadVo) {
        trashIntegralRecoadService.recordExport(response,trashIntegralRecoadVo);
    }

    @RequestMapping("/recordRank")
    public BaseResult recordRank(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                 String communityName,
                                 String type,
                                 Integer officer,
                                 String start_time,
                                 String end_time,
                                 String desc
    ) {
        if (ObjectUtils.isNotEmpty(officer)
                && !"号".equals(type)){
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return trashIntegralRecoadService.recordRank(pageNum, pageSize, communityName, type,officer,start_time,end_time,desc);
    }

    @RequestMapping("/recordRankExport")
    public void recordRankExport(HttpServletResponse response,String communityName,String type,Integer officer,String start_time,String end_time,String desc) {
        if (ObjectUtils.isNotEmpty(officer)
                && !"号".equals(type)){
            throw new DefinedException(BaseResult.build(StatusCode.PARAMETER_WRONG));
        }
        trashIntegralRecoadService.recordRankExport(response,communityName, type,officer,start_time,end_time,desc);
    }
    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":{"tirId":1,"userId":"158502014539731","houseAddr":"1,聚金万佳苑,10栋32-6","createTime":"2020-04-20 12:20:47","delivererId":"158502014539731","gotIntegral":20,"totalIntegral":500,"trashType":1,"deliverWeight":20,"deviceId":"431966353339464D05D8FF33"}}
     * @catalog 社区后台管理/智能垃圾箱
     * @title 投递积分记录详情
     * @method get
     * @param id 必须 Integer 记录ID
     * @description 积分记录详情
     * @url /cms/admin/trashCan/recordDetail
     */
    @RequestMapping("/recordDetail")
    public BaseResult recordDetail(Integer id) {
        if (id == null){
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return BaseResult.ok(trashIntegralRecoadService.detail(id));
    }
    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data": null}
     * @catalog 社区后台管理/智能垃圾箱
     * @title 删除投递积分记录
     * @method delete
     * @param id 必须 Integer 记录ID
     * @description 删除积分记录
     * @url /cms/admin/trashCan/recordDel
     */
    @RequestMapping("/recordDel")
    public BaseResult recordDel(Integer id) {
        if (id == null){
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return BaseResult.ok(trashIntegralRecoadService.recordDel(id));
    }
    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data": null}
     * @catalog 社区后台管理/智能垃圾箱
     * @title 启用或者停用设备
     * @method post
     * @param id 必须 String 设备号
     * @description 启用或者停用设备
     * @url /cms/admin/trashCan/recordDel
     */
    @RequestMapping("/useOrStop")
    public BaseResult useOrStop(String id) {
        if (StringUtils.isBlank(id)){
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return trashCanService.useOrStop(id);
    }

    /**
     * showdoc
     *
     * @return "status":200,"msg":"SUCCESS","data": null}
     * @catalog 社区后台管理/智能垃圾箱
     * @title 添加或者修改分类桶
     * @method post
     * @description 添加或者修改智能垃圾箱
     * @url /cms/admin/trashCan/insertOrUpdate
     */
    @RequestMapping("/insertOrUpdate")
    public BaseResult insertOrUpdate(@RequestBody @Valid TrashCan trashCan) {
        return BaseResult.ok(trashCanService.insertOrUpdate(trashCan));
    }


}
